using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using QuoteTree;
using System.IO;

public partial class setNodeAttributes : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        this.Response.Cache.SetCacheability(HttpCacheability.NoCache);
        QTree tree; string nodePath = "";
        if (this.Session["tree"] != null)
        {            
            tree = this.Session["tree"] as QTree;

            if (this.Request.QueryString["nodePath"] != null && this.Request.QueryString["nodePath"].ToString() != "")
                nodePath = this.Request.QueryString["nodePath"].ToString();
            else
            {
                try
                {
                    Response.Write(Decimal.Round(tree.Root.total(), 0));
                }
                catch (Exception) { Response.Write("Error"); }
                return;
            }
        }
        else return;

        //Check for the "selected" attribute and apply to session  tree
        if (this.Request.QueryString["selected"] != null && this.Request.QueryString["selected"].ToString() != "")
        {
            if (this.Request.QueryString["selected"].ToString() == "true")
            {
                try
                {
                    tree.GetNodeFromPath(nodePath).selected = true;
                    //Response.Write("'Selected' set to true");
                    //Response.Write(nodePath);
                }
                catch (Exception) { }
            }
            else
            {
                try
                {
                    tree.GetNodeFromPath(nodePath).selected = false;
                    //Response.Write("'Selected' set to false");
                    //Response.Write(nodePath);
                }
                catch (Exception) { }

            }
        }
        try
        {
            Response.Write(Decimal.Round(tree.Root.total(), 0));
        }
        catch (Exception) { Response.Write("Error"); }
    }
}
